// The form contains fields for many pagiantion optiosn so you can 
// quickly see the resuluts of the different options.
// This function creates an option object for the pagination function.
// This will be be unnecessary in your application where you just set
// the options once.
$(function() {
		var items_on_page = 30;
		var pages_step = 5;
		
		get_data_by_name(1, 30);
		$.ajax({
			type: "POST",
			url: "/tuans/tuan_total_by_name",
			data: {
			name: $("#tuanname").val(),
			type: "get"},
			success: function(total)
			{
				$("#paging").jpaging({
					all_items_num: total,
					callback: get_data_by_name,
					items_on_page: items_on_page,
					pages_step: pages_step
				});
			}
		});

		$("#tuan_inner_search").click(function(){
			var zhuangtai = new Array();
			var universities = new Array();
			$.each($('input[name=zhuangtai]:checked'), function(){ zhuangtai.push($(this).val());});
			$.each($('input[name=university]:checked'), function(){ universities.push($(this).val());});
			get_data(1, 30);
                        $.ajax({
                                type: "POST",
                                url: "/tuans/tuan_total",
                                data: {zhuangtai: zhuangtai,
                                universities : universities,
                                type: "get"},
                                success: function(total)
                                {
                                        $("#paging").jpaging({
                                                all_items_num: total,
                                                callback: get_data,
                                                items_on_page: items_on_page,
                                                pages_step: pages_step
                                        });
                                }
                        });
                        return false;
                });


		function get_data(start_index, end_index){
			var zhuangtai = new Array();
			var universities = new Array();
			$.each($('input[name=zhuangtai]:checked'), function(){ zhuangtai.push($(this).val());});
			$.each($('input[name=university]:checked'), function(){ universities.push($(this).val());});
			start_index = start_index - 1;
			end_index = end_index - 1;
			$.ajax({
				type: "POST",
				url: "/tuans/tuan_paging",            
				data: {start_index: start_index,
				end_index: end_index,
                                zhuangtai: zhuangtai,
                                universities : universities,
				type: "get"},
				success: function(html)
				{                  
					$("#demo_tbl").html(html);
					$('html, body').animate({ scrollTop: 0 }, 'slow');
				}
			});			
		}
		function get_data_by_name(start_index, end_index){
			start_index = start_index - 1;
			end_index = end_index - 1;
			$.ajax({
				type: "POST",
				url: "/tuans/tuan_paging_by_name",            
				data: {start_index: start_index,
				end_index: end_index,
				name: $("#tuanname").val(),
				type: "get"},
				success: function(html)
				{                  
					$("#demo_tbl").html(html);
					$('html, body').animate({ scrollTop: 0 }, 'slow');
				}
			});			
		}

});
